// Copyright (C) 2004-2009
// Alex Turbov, Igor Veresov
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/thread/unilock.hpp>

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

using namespace boost;

BOOST_AUTO_TEST_CASE(test_unilock_1)
{
    typedef unilock<parameterized_scheduler<default_scheduler<exclusive_lock>, int> > lock_t;
    lock_t l;
    l.lock(123, exclusive_lock::lock);
    BOOST_CHECK_EQUAL(l.try_lock(123, exclusive_lock::lock), false);
    l.unlock(123/*, exclusive_lock::lock*/);
}

BOOST_AUTO_TEST_CASE(test_unilock_2)
{
    typedef unilock<
        parameterized_scheduler<
            parameterized_scheduler<
                default_scheduler<exclusive_lock>
              , int
              >
          , char
          >
      > lock_t;
    lock_t l;
    l.lock('a', 123/*, exclusive_lock::lock*/);
    BOOST_CHECK_EQUAL(l.try_lock('a', 123, exclusive_lock::lock), false);
    BOOST_CHECK_EQUAL(l.try_lock('b', 124, exclusive_lock::lock), true);
    l.unlock('b', 124/*, exclusive_lock::lock*/);
    l.unlock('a', 123/*, exclusive_lock::lock*/);
}
